package com.gui.controller;


import com.gui.exception.DIYExceptionHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * CustomizeExceptionHandler
 *
 * @author guigu
 * @QQ 1170258867
 * @date 2020/6/13
 * @description 不生效 一脸懵逼
 */
@ControllerAdvice
public class CustomizeExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ModelAndView handle(Exception e){
        ModelAndView modelAndView = new ModelAndView();
        if (e instanceof DIYExceptionHandler){
            modelAndView.addObject("message",e.getMessage());
        }else {
            modelAndView.addObject("message","服务器炸了");
        }
        modelAndView.setViewName("error/server");
        return modelAndView;
    }
}
